var sex = '';
var firstname =  '';
var lastname =  '';
var defaul =  '';
var phone =  '';
var email =  '';
var usr =  '';
var weblanguage = ''
var invoicelanguage = ''
var octopusNo = '';
$(function(){
    init();
})

function init(){
    if(sessionStorage.getItem("sex") != null ){

        sex = sessionStorage.getItem("sex");
        firstname = sessionStorage.getItem("firstname");
        lastname = sessionStorage.getItem("lastname");
        defaul = sessionStorage.getItem("defaul");
        phone = sessionStorage.getItem("phone");
        email = sessionStorage.getItem("email");
        usr = sessionStorage.getItem("usr");
        weblanguage = sessionStorage.getItem("weblanguage");
        invoicelanguage = sessionStorage.getItem("invoicelanguage");
        octopusNo = sessionStorage.getItem("octopusNo");
    }
    console.log(sex+":::")
    $('.email').html(email);
    //$('.name').html(email);
    $('#male').val(sex);
    $('#name').val(firstname);
    $('#surname').val(lastname);
    $('#tel').val(phone);
    $('#octopus').val();
    $('#English').val(weblanguage);
    $('#invoice').val(invoicelanguage);
    $('#octopus').val(octopusNo);
}


$('.pdfBtn').on('tap',function(){
    location.href="http://www.octopus.com.hk/web09_include/_document/en/rewards_terms_and_conditions.pdf";
})
function save() {
    sex = $('#male').val();
    firstname = $('#name').val();
    lastname = $('#surname').val();
    weblanguage = $('#English').val();
    invoicelanguage = $('#invoice').val();
    phone = $('#tel').val();
    email = $('.email').html();
    octopusNo = $('#octopus').val();
    var arr = {
        hs_action_id: 'save',
        hf_s_id: 'WD11',
        hf_srv_id: 'Cv_jcus_adm_cac',
        hs_title_id: sex,
        hs_first_name: firstname,
        hs_family_name: lastname,
        /*hs_date_of_birth: '31%2F12%2F2011&',*/
        hs_web_loc_id: weblanguage,
        hs_octopus_no: octopusNo,
        hs_view_pdt_mode: 'IMAGE',
        hs_inv_loc_id: invoicelanguage,
        hs_main_phone: phone,
      /*  hs_addi_phone: 94569456,*/
       /* hs_fax: 97899789,*/
        hs_main_email: email,
        hs_addi_email: '',
        hs_pwd: '',
        hs_cus_dft_cmt: ''
         };
         getAjaxRequest(arr,function(result){
            if( result.bs_result == "OK" ){
                mui.toast("Save Successfully");
                closeToast();
                getInfo();
                //init();
                var session = ["sex","firstname","lastname","defaul","phone","email","octopusNo"];
                sessionStorageRemoveAll(session);
            }else {
                mui.toast("Save Faily");
                closeToast();
            }

         });
}


function closeToast(){
    setTimeout(function(){
        $('.mui-toast-container').remove();
    },1000)
}

$('.save').on('tap',function(){
    save();
})